package com.gujiangbo.channel;

import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/5/7 13:54
 * @Version: 1.0
 * @Description: 通道之间的数据传输
 */
public class JavaFileChannelTransFrom {

    public static void main(String[] args) throws Exception {
        RandomAccessFile aFile = new RandomAccessFile("/Users/gujiangbo/Desktop/project/study-nio/src/main/resources/file.txt", "rw");
        FileChannel aChannel = aFile.getChannel();

        RandomAccessFile bFile = new RandomAccessFile("/Users/gujiangbo/Desktop/project/study-nio/src/main/resources/file1.txt", "rw");
        FileChannel bChannel = bFile.getChannel();
        long position = 0;
        long count = aChannel.size();
        bChannel.transferFrom(aChannel, position, count);
        aFile.close();
        bFile.close();
        System.out.println("over");


    }
}
